import 'package:flutter/material.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/entities/enum_entity.dart';
import 'package:library_base/entities/order_detail_entity.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/double_ext.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:module_dispatcher/page/progress/progress_order_detail/progress_detail_controller.dart';


class ProgressDetailPage extends StatefulWidget {
  const ProgressDetailPage({Key? key}) : super(key: key);

  @override
  _ProgressDetailPageState createState() => _ProgressDetailPageState();
}

class _ProgressDetailPageState extends BaseState<ProgressDetailPage, ProgressDetailController> {

  late OrderDetailEntity orderDetailEntity;

  @override
  ProgressDetailController registerController() => Get.put(ProgressDetailController());

  @override
  void onCreate() {
    super.onCreate();
    setTitle(MultiLanguage.orderDetails);
    setNavigationBarColor(ThemeUtil.getTheme().secondaryBgColor(),);
    orderDetailEntity = Get.arguments['OrderDetailEntity'];
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return Container(
      color: ThemeUtil.getTheme().secondaryBgColor(),
      child: Column(children: [
        Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
                width: double.infinity,
                color: ThemeUtil.getTheme().colorScheme.secondary,
                padding:edgeAll24, child: Text(MultiLanguage.basicInformation.tr,style: sixthTextColor28)),
            line3,
          ],
        ),
        Container(padding: edgeLR24,
          color: ThemeUtil.getTheme().colorScheme.secondary,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              gapH24,
              Row(children: [
                Text(MultiLanguage.orderNumber.tr,style: normalTextColor28,),
                Expanded(child: Text(orderDetailEntity.orderNumber,style: normalTextColor28,textAlign: TextAlign.end)),
              ]),
              gapH24,
              Row(children: [
                Text(MultiLanguage.clientSName.tr,style: normalTextColor28,),
                Expanded(child: Text(orderDetailEntity.consignee,style: normalTextColor28,textAlign: TextAlign.end)),
              ]),
              gapH24,
              Row(children: [
                Text(MultiLanguage.shippingAddress.tr,style: normalTextColor28,),
                Expanded(child: Text(orderDetailEntity.addressDetail,style: normalTextColor28,textAlign: TextAlign.end)),
              ]),
              gapH24,
              Row(children: [
                Text(MultiLanguage.contactNumber.tr,style: normalTextColor28,),
                Expanded(child: Text(orderDetailEntity.mobilePhone,style: normalTextColor28,textAlign: TextAlign.end)),
              ]),
              gapH24,
              Row(children: [
                Text(MultiLanguage.deliveryDate.tr,style: normalTextColor28,),
                Expanded(child: Text(orderDetailEntity.stationTime,style: normalTextColor28,textAlign: TextAlign.end)),
              ]),
              gapH24,
            ],
          ),
        ),
        gapH18,
        Container(
          color: ThemeUtil.getTheme().colorScheme.secondary,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: _buildForm(),
          ),
        ),
      ]),
    );
  }

  List<Widget> _buildForm(){
    List<Widget> widgets = [];
    widgets.add(Container(
      padding: edgeV24,
      child: Row(children: [
        Expanded(child: Text(MultiLanguage.commodity.tr,style: sixthTextColor28,textAlign: TextAlign.center)),
        Expanded(child: Text(MultiLanguage.coding.tr,style: sixthTextColor28,textAlign: TextAlign.center)),
        Expanded(child: Text("${MultiLanguage.weightKg.tr}${SPUtil.isJin.unitStrZhWithBracket()}",style: sixthTextColor28,textAlign: TextAlign.center)),
      ]),
    ));
    widgets.add(line1);
    widgets.addAll(orderDetailEntity.orderGoodsResList.buildItem(
            (index,data){
          return Container(
            padding: edgeV24,
            child: Row(
              children: [
                Expanded(child: Text(data.goodsName,style: normalTextColor28,textAlign: TextAlign.center)),
                Expanded(child: Text(data.goodsBarCode,style: normalTextColor28,textAlign: TextAlign.center)),
                Expanded(child: Text(data.sumWeight.numAsUnitStr(),style: normalTextColor28,textAlign: TextAlign.center)),
              ],
            ),
          );
        },
        dividingLine: (){
          return line1;
        },divideType: DivideType.MIDDLE_WITH_BOTTOM
    ));
    return widgets;
  }
}
